<?php
/*
 * Created on Nov 16, 2011
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
require_once("bizlayer/player_mgmt.php");

session_start();

$inSession = isset($_SESSION["me"]);
$loginFailed = false;


if(isset($_POST["emailaddress"]) && trim($_POST["emailaddress"]) != "" && isset($_POST["password"]) && trim($_POST["password"]) != ""){
	$emailAddr = $_POST["emailaddress"];
	$password = md5($_POST["password"]);
	
	$me = PlayerMgmt::login($emailAddr,$password);
	if($me != null){
		
		session_regenerate_id();
		$inSession = true;
		$loginFailed = false;	
		$_SESSION["me"] = $me;
		if($_SESSION["me"]->locked == 1)
			header(sprintf("Location:%s?locked=true",$_SERVER["HTTP_REFERER"]));
		else if($_SESSION["me"]->verified == 0)
			header("Location:update_password.php");
		else{
			header(sprintf("Location:%s",$_SERVER["HTTP_REFERER"]));	
		}
		
	}
	else{
		$inSession = false;
		$loginFailed = true;
		header(sprintf("Location:%s?loginfailed=true",$_SERVER["HTTP_REFERER"]));
	}	
}
 
?>
